package com.lb.videoplay.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.lb.videoplay.R;
import com.lb.videoplay.model.VideoModel;
import com.lb.videoplay.utils.SampleCoverVideo;

import java.util.ArrayList;
import java.util.List;

public class VideoAdapter extends BaseAdapter {

    public static final String TAG = "ListNormalAdapter22";

    private LayoutInflater inflater;
    private Context context;
    private List<VideoModel> mList = new ArrayList<>();


    public VideoAdapter(Context context, List<VideoModel> list) {
        super();
        this.context = context;
        inflater = LayoutInflater.from(context);
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_featured, null);
            holder.gsyVideoPlayer = (SampleCoverVideo) convertView.findViewById(R.id.video_item_player);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.gsyVideoPlayer.loadCoverImage(mList.get(position).getPicUrl(), R.drawable.startup_pic);

        holder.gsyVideoPlayer.setUpLazy(mList.get(position).getVideoUrl(), true, null, null, "这是title");
        //增加title
        holder.gsyVideoPlayer.getTitleTextView().setVisibility(View.GONE);
        //设置返回键
        holder.gsyVideoPlayer.getBackButton().setVisibility(View.GONE);
        //设置全屏按键功能
        holder.gsyVideoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.gsyVideoPlayer.startWindowFullscreen(context, false, true);
            }
        });
        //防止错位设置
        holder.gsyVideoPlayer.setPlayTag(TAG);
        holder.gsyVideoPlayer.setPlayPosition(position);
        //是否根据视频尺寸，自动选择竖屏全屏或者横屏全屏
        holder.gsyVideoPlayer.setAutoFullWithSize(true);
        //音频焦点冲突时是否释放
        holder.gsyVideoPlayer.setReleaseWhenLossAudio(false);
        //全屏动画
        holder.gsyVideoPlayer.setShowFullAnimation(true);
        //小屏时不触摸滑动
        holder.gsyVideoPlayer.setIsTouchWiget(false);
        //全屏是否需要lock功能
        return convertView;

    }

    class ViewHolder {
        SampleCoverVideo gsyVideoPlayer;
    }

}
